Skip to content

feat(megatron): report peak memory for log_probs and actor_train - #2304

Open
EazyReal wants to merge 1 commit into
THUDM:mainfrom
EazyReal:upstream-pr/slime-peak-memory
Open

feat(megatron): report peak memory for log_probs and actor_train#2304
EazyReal wants to merge 1 commit into
THUDM:mainfrom
EazyReal:upstream-pr/slime-peak-memory

Conversation

@EazyReal

Copy link
Copy Markdown
Contributor

Summary

  • print_memory samples current allocation only at fixed lifecycle points, so it cannot expose a phase's high-water mark and an OOM can happen before the next report
  • add accelerator-aware report_peak_memory(phase): reset peak stats on entry and log peak allocated/reserved memory in a finally block, so an OOMing phase still reports its high-water mark
  • wrap each executed ref/teacher/actor log_probs forward and actor_train, composed with the existing timer scopes; a reused or skipped actor forward emits no separate log_probs report
  • support the allocator APIs exposed by Slime's CUDA/ROCm and MUSA backends; registered accelerators without those APIs continue without peak reporting
  • intentionally scope the reset to the current device and require non-nested scopes, because an inner reset would discard an outer phase's peak

Measured on a 128x H100 DeepSeek-V4-Flash run at 262,144-token context: the finally-path report attributed a 132k-context log_probs OOM to 25 GiB of retained activations. The OOM traceback alone did not show the phase's high-water mark.

Testing

  • python tests/test_accelerator.py — 12 passed; covers reset-before-body, exact GB/log formatting, reporting on exceptions without swallowing them, unsupported-accelerator fallback, and CUDA/MUSA capability detection
  • black --line-length 119, ruff check, and isort --profile=black pass on all touched files

print_memory samples current allocation only at fixed lifecycle points, so it cannot show a phase high-water mark and an OOM can happen before the next report. Add accelerator-aware peak reporting in a finally block and compose it with the existing log_probs and actor_train timers.

Accelerators without peak-memory support keep executing without the report. CUDA/ROCm and MUSA expose the required allocator APIs.

Measured on a 128x H100 DeepSeek-V4-Flash run at 262,144-token context: the finally-path report attributed a 132k-context log_probs OOM to 25 GiB of retained activations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant